package edu.calvin.djs32.cs214.interpreters.frontend;

import static org.junit.Assert.assertEquals;

import org.antlr.runtime.ANTLRStringStream;
import org.antlr.runtime.RecognitionException;
import org.junit.Before;
import org.junit.Test;

import edu.calvin.cs214.hobbes2008.IntegerTIR;
import edu.calvin.cs214.hobbes2008.StringTIR;


public class Hobbes2008FrontEndTest {
	private Hobbes2008FrontEnd myFrontEnd;
	@Before
	public void setUp() {
		myFrontEnd = new Hobbes2008FrontEnd();
	}
	
	@Test
	public void shouldProcessIntegerProgram() throws RecognitionException {
		assertEquals(new IntegerTIR(123), myFrontEnd.process(new ANTLRStringStream("123")));
		assertEquals(new IntegerTIR(-123), myFrontEnd.process(new ANTLRStringStream("-123")));
		assertEquals(new IntegerTIR(0x123f), myFrontEnd.process(new ANTLRStringStream("0x123f")));
		assertEquals(new IntegerTIR(5), myFrontEnd.process(new ANTLRStringStream("+5")));
	}
	
	@Test
	public void shouldProcessStringProgram() throws RecognitionException {
		assertEquals(new StringTIR("foo"), myFrontEnd.process(new ANTLRStringStream("'foo'")));
		assertEquals(new StringTIR("foo bar"), myFrontEnd.process(new ANTLRStringStream("'foo bar'")));
		assertEquals(new StringTIR(" "), myFrontEnd.process(new ANTLRStringStream("' '")));
	}

}
